#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "fcntl.h"
#include "errno.h"
#include "string.h"
#include "signal.h"
#include "netinet/in.h"
#include "arpa/inet.h"
#include "sys/socket.h"
#include "sys/types.h"
#include "sys/ioctl.h"

#define	MAX_LENTH	1500
#define	IP			"127.0.0.1"
#define	PORT		9734



int main(int argc, char *argv[])
{
	//printf("Hello, world\n");
	struct sockaddr_in addr;
	int sockfd, ret;
	char snd_buf[MAX_LENTH];
	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr(IP);
	addr.sin_port = PORT;

	sockfd = socket(AF_INET, SOCK_DGRAM, 0);
	if (sockfd == -1)
	{
		perror("socket");
		exit(EXIT_FAILURE);
	}
	ret = connect(sockfd, (struct sockaddr *) &addr, sizeof(addr));
	if (ret == -1)
	{
		perror("connect");
		exit(EXIT_FAILURE);
	}
	while (1)
	{
		printf("input msg to send:");
		memset(snd_buf, '\0', MAX_LENTH);
		fgets(snd_buf, MAX_LENTH-1, stdin);
		write(sockfd, snd_buf, MAX_LENTH-1);
	}
	return 0;
}

